package com.example.student;

import android.os.Bundle;
import android.util.Log;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.google.android.material.bottomnavigation.BottomNavigationView;

public class Home extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        //初始化底部导航栏
        BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
        bottomNavigationView.setOnItemSelectedListener(item -> {
            int itemId = item.getItemId();
            if (itemId == R.id.nav_course_selection) {
                Bundle bundle = new Bundle();
                bundle.putInt("student_id", getIntent().getIntExtra("student_id", -1));
                CourseSelection courseSelection = new CourseSelection();
                courseSelection.setArguments(bundle);
                loadFragment(courseSelection);
                return true;
            } else if (itemId == R.id.nav_course_schedule) {
                loadFragment(new CourseSchedule());
                return true;
            } else if (itemId == R.id.nav_profile) {
                Bundle bundle = new Bundle();
                bundle.putInt("student_id", getIntent().getIntExtra("student_id", -1));
                Profile profile = new Profile();
                profile.setArguments(bundle);
                loadFragment(profile);
                return true;
            }
            return false;
        });

        // 默认加载选课信息页面
        if (savedInstanceState == null) {
            bottomNavigationView.setSelectedItemId(R.id.nav_course_selection);
        }

    }

    private void loadFragment(Fragment fragment) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.fragment_container, fragment);
        transaction.commit();
    }
}